package models;

import helpers.StringHelper;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Id;

import com.googlecode.objectify.annotation.Cached;
import com.googlecode.objectify.annotation.Indexed;
import com.googlecode.objectify.annotation.Unindexed;

@SuppressWarnings("serial")
@Cached
public class DealModel implements Serializable, Comparable<DealModel> {
	@Id
	private String dealId = "";

	/**
	 * NV Kinh Doanh
	 */
	@Unindexed
	private String username = "";

	/**
	 * Mã phụ lục hợp đồng
	 */
	@Unindexed
	private String contractCode = "";

	@Unindexed
	private String name = "";

	@Unindexed
	private String alias = "";

	@Unindexed
	private String shortName = "";

	@Unindexed
	private String abbreviation = "";

	@Indexed
	private String city = "";

	@Indexed
	private String category = "";

	/**
	 * 0: Phiếu giấy 1: Sản phẩm
	 */
	@Unindexed
	private int productType = 0;

	/**
	 * Khi tạo thì lưu vào doc.
	 * */
	@Indexed
	private Date doc = new Date();

	/**
	 * Khi sửa thì lưu ngày sửa vào update.
	 * */
	@Indexed
	private Date update = new Date();

	/**
	 * Khi chọn đưa deal lên top thì update vào dateToOrder
	 * */
	@Indexed
	private Date dateToOrder = new Date();

	@Indexed
	private Date startTime = new Date();

	@Indexed
	private Date endTime = new Date();

	/**
	 * 0: Chưa kích hoạt 1: Đang kích hoạt 2: Đang chạy 3: Kết thúc 4: Đã khóa
	 * 5: Hoàn thành
	 */
	@Indexed
	private int status = 2;

	/**
	 * 0: Deal thường 1: Marketing
	 */
	@Indexed
	private int dealType = 0;

	@Unindexed
	private int userMaximum = 10;

	@Unindexed
	private int limit = 100;

	/**
	 * Hình thức giao 0: Giao tận nơi 1: Giao tại công ty 2: Cả hai
	 */
	@Unindexed
	private int shipType = 2;

	@Indexed
	private Date expireTime = new Date();

	@Unindexed
	private String webTitle = "";

	@Unindexed
	private boolean displayTime = true;

	@Unindexed
	private String imageDeal = "";

	@Unindexed
	private String imageSlideshow = "";

	@Unindexed
	private boolean displayMap = true;

	@Unindexed
	private String imageMap = "";

	@Unindexed
	private String mapInformation = "";

	@Unindexed
	private String addressInformation = "";

	@Unindexed
	private boolean hasVoucher = false;

	@Unindexed
	private String description = "";

	@Unindexed
	private String dealCondition = "";

	@Unindexed
	private String content = "";

	@Unindexed
	private String note = "";

	@Unindexed
	private int price = 0;

	@Unindexed
	private int priceDiscount = 0;

	@Unindexed
	private int priceImport = 0;

	@Unindexed
	private String notePrice = "";

	@Unindexed
	private int amount = 0;

	@Unindexed
	private int userAmount = 0;

	public int getUserAmount() {
		return userAmount;
	}

	public void setUserAmount(int userAmount) {
		this.userAmount = userAmount;
	}

	public Date getUpdate() {
		return update;
	}

	public void setUpdate(Date update) {
		this.update = update;
	}

	public Date getDateToOrder() {
		return dateToOrder;
	}

	public void setDateToOrder(Date dateToOrder) {
		this.dateToOrder = dateToOrder;
	}

	public boolean isDisplayMap() {
		return displayMap;
	}

	public void setDisplayMap(boolean displayMap) {
		this.displayMap = displayMap;
	}

	public boolean isHasVoucher() {
		return hasVoucher;
	}

	public void setHasVoucher(boolean hasVoucher) {
		this.hasVoucher = hasVoucher;
	}

	public int getLimit() {
		return limit;
	}

	public void setLimit(int limit) {
		this.limit = limit;
	}

	public String getMapInformation() {
		return mapInformation;
	}

	public void setMapInformation(String mapInformation) {
		this.mapInformation = mapInformation;
	}

	public String getAddressInformation() {
		return addressInformation;
	}

	public void setAddressInformation(String addressInformation) {
		this.addressInformation = addressInformation;
	}

	public Date getDoc() {
		return doc;
	}

	public void setDoc(Date doc) {
		this.doc = doc;
	}

	public int getPriceImport() {
		return priceImport;
	}

	public void setPriceImport(int priceImport) {
		this.priceImport = priceImport;
	}

	public String getSubName() {
		if (name.length() > 77) {
			String tmp = name.substring(0, 77);
			String[] split = tmp.split(" ");
			StringBuilder tmpName = new StringBuilder();
			for (int i = 0; i < (split.length - 1); i++) {
				tmpName.append(split[i] + " ");
			}
			tmpName.append("...");
			return tmpName.toString();
		} else {
			return name;
		}
	}

	public String getDealCondition() {
		return dealCondition;
	}

	public void setDealCondition(String dealCondition) {
		this.dealCondition = dealCondition;
	}

	public String getAlias() {
		if (alias.length() > 0) {
			return alias;
		} else {
			return StringHelper.replaceVietnamese(shortName);
		}
	}

	public void setAlias(String alias) {
		this.alias = alias;
	}

	public int getAmount() {
		return amount;
	}

	public void setAmount(int amount) {
		this.amount = amount;
	}

	public String getDealId() {
		return dealId;
	}

	public void setDealId(String dealId) {
		this.dealId = dealId;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getContractCode() {
		return contractCode;
	}

	public void setContractCode(String contractCode) {
		this.contractCode = contractCode;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getShortName() {
		return shortName;
	}

	public String getSubShortName() {
		if (shortName.length() > 28) {
			String tmp = shortName.substring(0, 28);
			String[] split = tmp.split(" ");
			StringBuilder tmpName = new StringBuilder();
			for (int i = 0; i < (split.length - 1); i++) {
				tmpName.append(split[i] + " ");
			}
			tmpName.append("...");
			return tmpName.toString();
		} else {
			return shortName;
		}
	}

	public void setShortName(String shortName) {
		this.shortName = shortName;
	}

	public String getAbbreviation() {
		return abbreviation;
	}

	public void setAbbreviation(String abbreviation) {
		this.abbreviation = abbreviation;
	}

	public String getCity() {
		return city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public String getCategory() {
		return category;
	}

	public void setCategory(String category) {
		this.category = category;
	}

	public int getProductType() {
		return productType;
	}

	public void setProductType(int productType) {
		this.productType = productType;
	}

	public Date getStartTime() {
		return startTime;
	}

	public void setStartTime(Date startTime) {
		this.startTime = startTime;
	}

	public Date getEndTime() {
		return endTime;
	}

	public void setEndTime(Date endTime) {
		this.endTime = endTime;
	}

	public Date getExpireTime() {
		return expireTime;
	}

	public void setExpireTime(Date expireTime) {
		this.expireTime = expireTime;
	}

	public int getStatus() {
		return status;
	}

	public void setStatus(int status) {
		this.status = status;
	}

	public int getDealType() {
		return dealType;
	}

	public void setDealType(int dealType) {
		this.dealType = dealType;
	}

	public int getUserMaximum() {
		return userMaximum;
	}

	public void setUserMaximum(int userMaximum) {
		this.userMaximum = userMaximum;
	}

	public int getShipType() {
		return shipType;
	}

	public void setShipType(int shipType) {
		this.shipType = shipType;
	}

	public String getWebTitle() {
		return webTitle;
	}

	public void setWebTitle(String webTitle) {
		this.webTitle = webTitle;
	}

	public boolean isDisplayTime() {
		return displayTime;
	}

	public void setDisplayTime(boolean displayTime) {
		this.displayTime = displayTime;
	}

	public String getImageDeal() {
		return imageDeal;
	}

	public void setImageDeal(String imageDeal) {
		this.imageDeal = imageDeal;
	}

	public String getImageSlideshow() {
		return imageSlideshow;
	}

	public void setImageSlideshow(String imageSlideshow) {
		this.imageSlideshow = imageSlideshow;
	}

	public String getImageMap() {
		return imageMap;
	}

	public void setImageMap(String imageMap) {
		this.imageMap = imageMap;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public String getNote() {
		return note;
	}

	public void setNote(String note) {
		this.note = note;
	}

	public int getPrice() {
		return price;
	}

	public void setPrice(int price) {
		this.price = price;
	}

	public int getPriceDiscount() {
		return priceDiscount;
	}

	public void setPriceDiscount(int priceDiscount) {
		this.priceDiscount = priceDiscount;
	}

	public String getNotePrice() {
		return notePrice;
	}

	public void setNotePrice(String notePrice) {
		this.notePrice = notePrice;
	}

	@Override
	public int compareTo(DealModel o) {
		// TODO Auto-generated method stub
		return Long.valueOf(o.dateToOrder.getTime()).compareTo(
				this.dateToOrder.getTime());
	}
}
